#! /bin/bash
PRESTO_HOME=/opt/cloudera/parcels/presto/bin/presto
if [[ $1 == "" ]];then
   TD_DATE=`date -d '1 days ago' "+%Y-%m-%d"`
else
   TD_DATE=$1
fi

/export/server/presto/bin/presto --catalog hive --server hadoop01:8090 --execute "
-- 1.每天/每月/每年各个校区的报名人数 分组标记1
insert into hive.zx_rpt.rpt_daily_school_apply_count
select
       year_code,
       month_code,
       day_code,

       school_id,
       school_name,

       apply_count,

       dt
from hive.zx_dm.dm_apply_theme
where time_type = 'day' and group_mark = 1 and dt = '${TD_DATE}';

-- 2.每天/每月/每年线上线下各个校区的报名人数 分组标记2
insert into hive.zx_rpt.rpt_daily_type_school_apply_count
select
       year_code,
       month_code,
       day_code,

       school_id,
       school_name,
       origin_type,

       apply_count,

       dt
from hive.zx_dm.dm_apply_theme
where time_type = 'day' and group_mark = 2 and dt = '${TD_DATE}';

-- 3.每天/每月/每年线上线下各个学科的报名人数 分组标记3
insert into hive.zx_rpt.rpt_daily_type_subject_apply_count
select
       year_code,
       month_code,
       day_code,

       origin_type,
       subject_id,
       subject_name,

       apply_count,

       dt
from hive.zx_dm.dm_apply_theme
where time_type = 'day' and group_mark = 3 and dt = '${TD_DATE}';

-- 4.每天/每月/每年线上线下各个校区各个学科的报名人数 分组标记4
insert into hive.zx_rpt.rpt_daily_type_school_subject_apply_count
select
       year_code,
       month_code,
       day_code,

       school_id,
       school_name,
       origin_type,
       subject_id,
       subject_name,

       apply_count,

       dt
from hive.zx_dm.dm_apply_theme
where time_type = 'day' and group_mark = 4 and dt = '${TD_DATE}';

-- 5.每天/每月/每年线上线下各个来源渠道的报名人数 分组标记5
insert into hive.zx_rpt.rpt_daily_type_channel_apply_count
select
       year_code,
       month_code,
       day_code,

       origin_type,
       origin_channel,

       apply_count,

       dt
from hive.zx_dm.dm_apply_theme
where time_type = 'day' and group_mark = 5 and dt = '${TD_DATE}';

-- 6.每天/每月/每年线上线下各个咨询中心的报名人数 分组标记6
insert into hive.zx_rpt.rpt_daily_type_department_apply_count
select
       year_code,
       month_code,
       day_code,

       origin_type,
       department_id,
       department_name,
       apply_count,

       dt
from hive.zx_dm.dm_apply_theme
where time_type = 'day' and group_mark = 6 and dt = '${TD_DATE}';

-- 7.每天/每月/每年线上线下的报名人数,意向人数,有效线索人数 分组标记7
insert into hive.zx_rpt.rpt_daily_type_apply_rate
select
       year_code,
       month_code,
       day_code,

       origin_type,

       apply_count,
       intention_count,
       valid_thread_count,

       dt
from hive.zx_dm.dm_apply_theme
where time_type = 'day' and group_mark = 7 and dt = '${TD_DATE}';"